﻿function Widget_Labpixies(obj)
{
   this.initializeBase(obj);
}
Widget_Labpixies.prototype = new WidgetInstance;

Widget_Labpixies.prototype.Edit = function()
{
   if (myTabs.hasRequiredTabPermission(this.Tab, TabAccessLevel.Widget_Edit))
   {
      this.Widget.InstanceEdit("s" + this.id + "_embed");
   }
   else   
   {
      alert("You do not have the required permission");
   }
}
 
 
Widget_Labpixies.prototype.Save = function()
{
   if (myTabs.hasRequiredTabPermission(this.Tab, TabAccessLevel.Widget_Edit))
   {
      if (this.Setting.Embed.value.length < 1)
      {
         alert("Please enter the embed string from Labpixies");
         this.Setting.Embed.focus();
         return;
      }
      
      var Dict = new Object();
      Dict.Embed = this.Setting.Embed.value;
      
      JSON.Widget_UpdateProperties(this.Widget.Tab.id, this.id, Dict);
      this.inEditMode = true;
      this.Edit();
      this.Refresh();
   }
   else
   {
      alert("You do not have the required permission");   
   }
}

Widget_Labpixies.prototype.Refresh = function()
{
   var val = this.Setting.Embed.value;
   if (val && val.length > 0)
   {
      this.WidgetDiv_BodySettings.style.display = "none";
      this.WidgetDiv_BodyContent.style.display = "";
      this.WidgetDiv_BodyContent.innerHTML = val;
   }
   else
   {
      this.inEditMode = false;
      this.Edit();
   }
}

Widget_Labpixies.prototype.Load = function()
{
   this.Widget.InstanceLoad();
   
   this.WidgetDiv_BodySettings = $get('wdivb' + this.id + '_s');
   this.WidgetDiv_BodyContent = $get('wdivb' + this.id + '_c');
   
   this.Setting = new Object();
   this.Setting.Embed = $get('s' + this.id + '_embed');
   
   
   if (this.Widget.obj.State)
   {
      //if there is state information
      var xotree = new XML.ObjTree();
      var xmlDoc = xotree.parseXML(this.Widget.obj.State);
      
      //1 values, Embed
      this.Setting.Embed.value = xmlDoc.state.Embed;
   }
   
   this.WidgetDiv_Command_Edit = document.getElementById("wdivc_edit" + this.Widget.id);
   
   this.Refresh();
               
   this.Widget.InstanceLoadComplete();
}